package com.scommunity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scommunity.admin.vo.EmpQO;
import com.scommunity.domain.Emp;
import com.scommunity.mapper.EmpMapper;
import com.scommunity.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements IEmpService {
    @Autowired
    EmpMapper empMapper;

    @Override
    public Emp login(String empAccount, String empPassword) {
        return empMapper.selectOne(new QueryWrapper<Emp>().eq("emp_account", empAccount).eq("emp_password", empPassword));
    }

    @Override
    public PageInfo<Emp> findPageInfoByCondition(EmpQO empQO, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Emp> emps = empMapper.findPageInfoByCondition(empQO);
        PageInfo<Emp> pageInfo = new PageInfo<>(emps);
        return pageInfo;
    }

    @Cacheable(value = "emps")
    @Override
    public List<Emp> getAll() {
        return empMapper.findAll();
    }

    @Override
    public Emp getInfoByEmpId(Long empId) {
        return empMapper.getInfoByEmpId(empId);
    }

    @CacheEvict(value = "emps", allEntries = true)
    @Override
    public void add(Emp emp) {
        empMapper.add(emp);
    }

    @CacheEvict(value = "emps", allEntries = true)
    @Override
    public void update(Emp emp) {
        empMapper.update1(emp);
    }

    @CacheEvict(value = "emps", allEntries = true)
    @Override
    public void del(String id) {
        empMapper.del(id);
    }

    @Override
    public int getStatuseById(String id) {
        return empMapper.getStatuseById(id);
    }

}
